package com.nanyang.tms.service.forecast.impl.flow;

import com.nanyang.common.core.domain.ApiRequest;
import com.nanyang.common.core.flow.context.TransHandlerContext;
import com.nanyang.common.core.flow.convert.TransConvert;
import com.nanyang.common.tool.utils.convert.BeanUtils;
import com.nanyang.tms.api.dto.request.forecast.ForecastInfoAddRequest;
import com.nanyang.tms.domain.forecast.context.CalculateWeightVolumeContext;
import com.nanyang.tms.domain.forecast.context.ForecastAddContext;
import com.nanyang.tms.domain.forecast.context.saveforecast.SaveForecastDeclareContext;

public class ForecastAddConvert implements TransConvert{

	@Override
	public TransHandlerContext convertRequest2Ctx(ApiRequest req, TransHandlerContext context) {
		ForecastInfoAddRequest forecastAddRequest=(ForecastInfoAddRequest)req;
		ForecastAddContext forecastAddContext=(ForecastAddContext) context;
		//计算计费重所需参数
		BeanUtils.copyProperties(forecastAddRequest, forecastAddContext.getCalculateWeightContext());
		forecastAddContext.getCalculateWeightContext().setCityCode(forecastAddRequest.getReceiver().getProvinceCode());
		BeanUtils.copyListProperties(forecastAddRequest.getVolumes(), forecastAddContext.getCalculateWeightContext().getCalculateWeightVolumeContexts(), CalculateWeightVolumeContext.class);
		//计算运费所需参数
		BeanUtils.copyProperties(forecastAddRequest, forecastAddContext.getCalculateFreightContext());
		//保存预报所需参数
		BeanUtils.copyProperties(forecastAddRequest, forecastAddContext.getSaveForecastContext());
		BeanUtils.copyProperties(forecastAddRequest.getReceiver(), forecastAddContext.getSaveForecastContext().getSaveForecastReceiverContext());
		BeanUtils.copyProperties(forecastAddRequest.getSender(), forecastAddContext.getSaveForecastContext().getSaveForecastSenderContext());
		BeanUtils.copyListProperties(forecastAddRequest.getDeclares(), forecastAddContext.getSaveForecastContext().getSaveForecastDeclareContexts(), SaveForecastDeclareContext.class);
		return forecastAddContext;
	}

}
